
export default class Progress {
    constructor() {
        let containerDiv = document.createElement("div")
        containerDiv.setAttribute("id", "container")

        let percentDiv = document.createElement("div")
        percentDiv.setAttribute("id", "per")

        document.body.appendChild(containerDiv)
        containerDiv.appendChild(percentDiv)

        this.containerDiv = containerDiv;
        this.percentDiv = percentDiv;
    }

    updatePercent(percent) {
        let width = this.containerDiv.offsetWidth;
        this.percentDiv.style.width = percent * width + "px"; //进度条元素长度
        this.percentDiv.style.textIndent = percent * width + 5 + "px"; //缩进元素中的首行文本
        // Math.floor:小数加载进度取整
        this.percentDiv.innerHTML = Math.floor(percent * width) + '%'; //进度百分比
    }

    hide() {
        document.body.removeChild(this.containerDiv)
    }
}







